<template>
  <el-container style="min-height: 100vh">
    <el-aside :width="sideWidth + 'px'" style="background-color: rgb(238, 241, 246) height: 100%">
      <Aside :isCollapse="isCollapse" :logoTextShow="logoTextShow"></Aside>
    </el-aside>
      
    <el-container>
      
      <el-header style=" border-bottom: 1px solid #ccc; ">
        <Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" :user="user"></Header>
      </el-header>

      <el-main>
        <router-view @refreshUser="getUser"></router-view>  
      </el-main>

    </el-container>
  </el-container>
</template>

<script>

import Aside from '../components/Aside'
import Header from '../components/Header'

export default {
  name: "Home",
  components:{Aside,Header},
  data() {
    return {
      collapseBtnClass: "el-icon-s-fold",
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true,
      user: {}
    };
  },
  created(){
    this.getUser()
  },
  methods: {
    collapse() {
      this.isCollapse = !this.isCollapse;
      if (this.isCollapse) {
        // 收缩
        this.sideWidth = 50;
        this.collapseBtnClass = "el-icon-s-unfold";
        this.logoTextShow = false;
      } else {
        // 展开
        this.sideWidth = 200;
        this.collapseBtnClass = "el-icon-s-fold";
        this.logoTextShow = true;
      }
    },
    getUser() {
      let user = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : ""
      //从后台获取User数据
      this.request.get("/user/" + user.id).then(res =>{
        this.user = res.data
        console.log('menus',this.user.menus);
      })
    },
    
  },
};
</script>

